@extends('layouts.app')

@section('content')
<div class="content content_channel">
	<div class="button">
		<button class="add_channel">添加渠道</button>
	</div>
	<table>
		<thead>
			<tr>
				<th>订单渠道</th><th>创建时间</th><th>操作</th>
			</tr>
		</thead>
		<tbody id="list">
		</tbody>
	</table>
</div>
@endsection

@section('scripts')
<script type="text/javascript">
	var baseUrl = 'types';

	params['page'] = 1;
	params['pageSize'] = 10;
    getList(baseUrl,params);
	$(function(){
		$('.page_content').on('click','.add_channel',function(){
			$.ajax({
		        type: "GET",
		        url: "/types/create",
		        dataType: "html",
		        success: function(res) {
					art.dialog({
						title: '添加渠道',
						width: '497px',
						lock: true,
						id: 'edit',
						content: res,
					});
				}
			});
		})

		$('#list').on('click','#edit',function(){
			var id = $(this).attr('data-id');
			$.ajax({
		        type: "GET",
		        url: "/types/edit/"+id,
		        dataType: "html",
		        success: function(res) {
					art.dialog({
						title: '添加商品',
						width: '497px',
						lock: true,
						id: 'edit',
						content: res,
					});
				}
			});
		})

		$('#list').on('click','#del',function(){
			var id = $(this).prev().attr('data-id');
			$.ajax({
		        type: "DELETE",
		        url: "/type/"+id,
		        dataType: "json",
		        success: function(res) {
		        	box.tipHover({ status: 0, msg: "删除成功" });
		        	// alert('删除成功');
    				getList(baseUrl,params);
				}
			});
		})

		$("body").on("click",".true",function(){
			var form = new Object();
			form.name = $('#name').val();
			var id = $(this).attr('data-id');
			if(id != '') {
				form.id = id;
			}
			if(form.name == "") {
				box.tipHover({ status: 0, msg: "渠道名称不能为空" });
				// alert('渠道名称不能为空');
				return false;
			}
			$.ajax({
		        type: "POST",
		        url: "/type",
		        dataType: "json",
		        data: form,
		        success: function(res) {
		        	art.dialog.list['edit'].close();
    				getList(baseUrl,params);
				},
				error:function(res){
					box.tipHover({ status: 0, msg: "渠道名称已存在！" });
					// alert('渠道名称已存在！')
				}
			});
		})
	})
</script>
@endsection